import PySimpleGUI as sg
import math


layout = [
    [sg.Input( key= '-INPUT-'), 
    sg.Spin(['km to mile','kg to pounds', 'sec to min','Cel to Fahren','Factorial','Decimal to Binary','Decimal to Octal','Decimal to Hexadecimal'], key='-UNITS-'), 
    sg.Button('Convert', key= '-CONVERT-')], #contains row for text and spin attribute for multiple choice selection
    [sg.Text('Output',key='-OUTPUT-')]
    
]
window = sg.Window('Converter', layout) #contains the title of the app along with how ui will look

while True:
    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break

    if event == '-CONVERT-':
        input_value = values['-INPUT-']
        if input_value.isnumeric():
            match values['-UNITS-']:
                case 'km to mile':
                    output = round(float(input_value) * 0.6214, 2)
                    ouput_string = f"{input_value} kilometres = {output} miles."
                case 'kg to pounds':
                    output = round(float(input_value) * 2.20462, 2)
                    ouput_string = f"{input_value} kilograms = {output} pounds."
                case 'sec to min':
                    output = round(float(input_value)/ 60, 2)
                    ouput_string = f"{input_value} seconds = {output} minutes."
                case 'Cel to Fahren':
                    output = float(input_value) * 1.8 + 32
                    ouput_string = f"{input_value} Celsius = {output} Fahrenheit."
                case 'Cel to Fahren':
                    output = float(input_value) * 1.8 + 32
                    ouput_string = f"{input_value} Celsius = {output} Fahrenheit."
                case 'Factorial':
                    output = math.factorial(int(input_value))
                    ouput_string = f"The Factorial of {input_value}  = {output}."
                case 'Decimal to Binary':
                    output = (bin(float(input_value))[2:])
                    ouput_string = f"The Binary equivalent of {input_value}  = {output}."
                case 'Decimal to Octal':
                    output = (oct(int(input_value))[2:])
                    ouput_string = f"The Octal equivalent of {input_value}  = {output}."
                case 'Decimal to Hexadecimal':
                    output = (hex(int(input_value))[2:])
                    ouput_string = f"The Hexadecimal equivalent of {input_value}  = {output}."

            window['-OUTPUT-'].update(ouput_string)
        else:
            window['-OUTPUT-'].update('Please Enter a Valid Number!')
        
         
window.close()


